package com.designpattern.builder;

/**
 * @author Liusr
 * @date 2023/3/29
 * @package com.designpattern.builder
 * @Description:
 */
public class Computer {

	private final String cpu;//必须
	private final String ram;//必须
	private final int usbCount;//可选
	private final String keyboard;//可选
	private final String display;//可选

	public Computer(Builder builder){
		this.cpu = builder.cpu;
		this.ram=builder.ram;
		this.usbCount=builder.usbCount;
		this.keyboard=builder.keyboard;
		this.display=builder.display;
	}

	//静态内部类
	public static class Builder{
		private String cpu;//必须
		private String ram;//必须
		private int usbCount;//可选
		private String keyboard;//可选
		private String display;//可选

		public Builder(String cpu, String ram){
			this.cpu = cpu;
			this.ram = ram;
		}

		public Builder setUsbCount(int usbCount) {
			this.usbCount = usbCount;
			return this;
		}

		public Builder setKeyboard(String keyboard) {
			this.keyboard = keyboard;
			return this;
		}

		public Builder setDisplay(String display){
			this.display = display;
			return this;
		}

		public Computer build(){
			return new Computer(this);
		}

		public String getCpu() {
			return cpu;
		}

		public String getRam() {
			return ram;
		}

		public int getUsbCount() {
			return usbCount;
		}

		public String getKeyboard() {
			return keyboard;
		}

		public String getDisplay() {
			return display;
		}
	}
}
